#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
Mikan その他・関数 パッケージ

Mikan Python Web Framework
"""

__author__ = "K.Sonohara"
__status__ = "develop"
__version__ = "0.0.0_7"
__date__    = "2013/02/24"
__license__ = 'LGPL'

# ------------------------------------------------------------
## インポート
# ------------------------------------------------------------
# Ptyhon
import traceback
import hashlib
from datetime import date
from gzip import GzipFile
import StringIO

# ESiPC
from esipc.resource.iniresource import ESiPCINIFileResourceBundle

# Mikan

# ------------------------------------------------------------
## 変数
# ------------------------------------------------------------
## リソース変数

# ------------------------------------------------------------
## 日本の祝日データ
#  
HOLIDAY_JP = {
	2001:{1:{1: u"元日",
	8: u"成人の日",},
	2:{11: u"建国記念の日",
	12: u"振替休日",},
	3:{20: u"春分の日",},
	4:{29: u"みどりの日",
	30: u"振替休日",},
	5:{3: u"憲法記念日",
	4: u"国民の休日",
	5: u"こどもの日",},
	7:{20: u"海の日",},
	9:{15: u"敬老の日",
	23: u"秋分の日",
	24: u"振替休日",},
	10:{8: u"体育の日",},
	11:{3: u"文化の日",
	23: u"勤労感謝の日",},
	12:{23: u"天皇誕生日",
	24: u"振替休日",},},
	2002:{1:{1: u"元日",
	14: u"成人の日",},
	2:{11: u"建国記念の日",},
	3:{21: u"春分の日",},
	4:{29: u"みどりの日",},
	5:{3: u"憲法記念日",
	4: u"国民の休日",
	5: u"こどもの日",
	6: u"振替休日",},
	7:{20: u"海の日",},
	9:{15: u"敬老の日",
	16: u"振替休日",
	23: u"秋分の日",},
	10:{14: u"体育の日",},
	11:{3: u"文化の日",
	4: u"振替休日",
	23: u"勤労感謝の日",},
	12:{23: u"天皇誕生日",},},
	2003:{1:{1: u"元日",
	13: u"成人の日",},
	2:{11: u"建国記念の日",},
	3:{21: u"春分の日",},
	4:{29: u"みどりの日",},
	5:{3: u"憲法記念日",
	4: u"国民の休日",
	5: u"こどもの日",},
	7:{21: u"海の日",},
	9:{15: u"敬老の日",
	23: u"秋分の日",},
	10:{13: u"体育の日",},
	11:{3: u"文化の日",
	23: u"勤労感謝の日",
	24: u"振替休日",},
	12:{23: u"天皇誕生日",},},
	2004:{1:{1: u"元日",
	12: u"成人の日",},
	2:{11: u"建国記念の日",},
	3:{20: u"春分の日",},
	4:{29: u"みどりの日",},
	5:{3: u"憲法記念日",
	4: u"国民の休日",
	5: u"こどもの日",},
	7:{19: u"海の日",},
	9:{20: u"敬老の日",
	23: u"秋分の日",},
	10:{11: u"体育の日",},
	11:{3: u"文化の日",
	23: u"勤労感謝の日",},
	12:{23: u"天皇誕生日",},},
	2005:{1:{1: u"元日",
	10: u"成人の日",},
	2:{11: u"建国記念の日",},
	3:{20: u"春分の日",
	21: u"振替休日",},
	4:{29: u"みどりの日",},
	5:{3: u"憲法記念日",
	4: u"国民の休日",
	5: u"こどもの日",},
	7:{18: u"海の日",},
	9:{19: u"敬老の日",
	23: u"秋分の日",},
	10:{10: u"体育の日",},
	11:{3: u"文化の日",
	23: u"勤労感謝の日",},
	12:{23: u"天皇誕生日",},},
	2006:{1:{1: u"元日",
	2: u"振替休日",
	9: u"成人の日",},
	2:{11: u"建国記念の日",},
	3:{21: u"春分の日",},
	4:{29: u"みどりの日",},
	5:{3: u"憲法記念日",
	4: u"国民の休日",
	5: u"こどもの日",},
	7:{17: u"海の日",},
	9:{18: u"敬老の日",
	23: u"秋分の日",},
	10:{9: u"体育の日",},
	11:{3: u"文化の日",
	23: u"勤労感謝の日",},
	12:{23: u"天皇誕生日",},},
	2007:{1:{1: u"元日",
	8: u"成人の日",},
	2:{11: u"建国記念の日",
	12: u"振替休日",},
	3:{21: u"春分の日",},
	4:{29: u"昭和の日",
	30: u"振替休日",},
	5:{3: u"憲法記念日",
	4: u"みどりの日",
	5: u"こどもの日",},
	7:{16: u"海の日",},
	9:{17: u"敬老の日",
	23: u"秋分の日",
	24: u"振替休日",},
	10:{8: u"体育の日",},
	11:{3: u"文化の日",
	23: u"勤労感謝の日",},
	12:{23: u"天皇誕生日",
	24: u"振替休日",},},
	2008:{1:{1: u"元日",
	14: u"成人の日",},
	2:{11: u"建国記念の日",},
	3:{20: u"春分の日",},
	4:{29: u"昭和の日",},
	5:{3: u"憲法記念日",
	4: u"みどりの日",
	5: u"こどもの日",
	6: u"振替休日",},
	7:{21: u"海の日",},
	9:{15: u"敬老の日",
	23: u"秋分の日",},
	10:{13: u"体育の日",},
	11:{3: u"文化の日",
	23: u"勤労感謝の日",
	24: u"振替休日",},
	12:{23: u"天皇誕生日",},},
	2009:{1:{1: u"元日",
	12: u"成人の日",},
	2:{11: u"建国記念の日",},
	3:{20: u"春分の日",},
	4:{29: u"昭和の日",},
	5:{3: u"憲法記念日",
	4: u"みどりの日",
	5: u"こどもの日",
	6: u"振替休日",},
	7:{20: u"海の日",},
	9:{21: u"敬老の日",
	22: u"国民の休日",
	23: u"秋分の日",},
	10:{12: u"体育の日",},
	11:{3: u"文化の日",
	23: u"勤労感謝の日",},
	12:{23: u"天皇誕生日",},},
	2010:{1:{1: u"元日",
	11: u"成人の日",},
	2:{11: u"建国記念の日",},
	3:{21: u"春分の日",
	22: u"振替休日",},
	4:{29: u"昭和の日",},
	5:{3: u"憲法記念日",
	4: u"みどりの日",
	5: u"こどもの日",},
	7:{19: u"海の日",},
	9:{20: u"敬老の日",
	23: u"秋分の日",},
	10:{11: u"体育の日",},
	11:{3: u"文化の日",
	23: u"勤労感謝の日",},
	12:{23: u"天皇誕生日",},},
	2011:{1:{1: u"元日",
	10: u"成人の日",},
	2:{11: u"建国記念の日",},
	3:{21: u"春分の日",},
	4:{29: u"昭和の日",},
	5:{3: u"憲法記念日",
	4: u"みどりの日",
	5: u"こどもの日",},
	7:{18: u"海の日",},
	9:{19: u"敬老の日",
	23: u"秋分の日",},
	10:{10: u"体育の日",},
	11:{3: u"文化の日",
	23: u"勤労感謝の日",},
	12:{23: u"天皇誕生日",},},
	2012:{1:{1: u"元日",
	2: u"振替休日",
	9: u"成人の日",},
	2:{11: u"建国記念の日",},
	3:{20: u"春分の日",},
	4:{29: u"昭和の日",
	30: u"振替休日",},
	5:{3: u"憲法記念日",
	4: u"みどりの日",
	5: u"こどもの日",},
	7:{16: u"海の日",},
	9:{17: u"敬老の日",
	22: u"秋分の日",},
	10:{8: u"体育の日",},
	11:{3: u"文化の日",
	23: u"勤労感謝の日",},
	12:{23: u"天皇誕生日",
	24: u"振替休日",},},
	2013:{1:{1: u"元日",
	14: u"成人の日",},
	2:{11: u"建国記念の日",},
	3:{20: u"春分の日",},
	4:{29: u"昭和の日",},
	5:{3: u"憲法記念日",
	4: u"みどりの日",
	5: u"こどもの日",
	6: u"振替休日",},
	7:{15: u"海の日",},
	9:{16: u"敬老の日",
	23: u"秋分の日",},
	10:{14: u"体育の日",},
	11:{3: u"文化の日",
	4: u"振替休日",
	23: u"勤労感謝の日",},
	12:{23: u"天皇誕生日",},},
	2014:{1:{1: u"元日",
	13: u"成人の日",},
	2:{11: u"建国記念の日",},
	3:{21: u"春分の日",},
	4:{29: u"昭和の日",},
	5:{3: u"憲法記念日",
	4: u"みどりの日",
	5: u"こどもの日",
	6: u"振替休日",},
	7:{21: u"海の日",},
	9:{15: u"敬老の日",
	23: u"秋分の日",},
	10:{13: u"体育の日",},
	11:{3: u"文化の日",
	23: u"勤労感謝の日",
	24: u"振替休日",},
	12:{23: u"天皇誕生日",},},
	2015:{1:{1: u"元日",
	12: u"成人の日",},
	2:{11: u"建国記念の日",},
	3:{21: u"春分の日",},
	4:{29: u"昭和の日",},
	5:{3: u"憲法記念日",
	4: u"みどりの日",
	5: u"こどもの日",
	6: u"振替休日",},
	7:{20: u"海の日",},
	9:{21: u"敬老の日",
	22: u"国民の休日",
	23: u"秋分の日",},
	10:{12: u"体育の日",},
	11:{3: u"文化の日",
	23: u"勤労感謝の日",},
	12:{23: u"天皇誕生日",},},
	2016:{1:{1: u"元日",
	11: u"成人の日",},
	2:{11: u"建国記念の日",},
	3:{20: u"春分の日",
	21: u"振替休日",},
	4:{29: u"昭和の日",},
	5:{3: u"憲法記念日",
	4: u"みどりの日",
	5: u"こどもの日",},
	7:{18: u"海の日",},
	9:{19: u"敬老の日",
	22: u"秋分の日",},
	10:{10: u"体育の日",},
	11:{3: u"文化の日",
	23: u"勤労感謝の日",},
	12:{23: u"天皇誕生日",},},
	2017:{1:{1: u"元日",
	2: u"振替休日",
	9: u"成人の日",},
	2:{11: u"建国記念の日",},
	3:{20: u"春分の日",},
	4:{29: u"昭和の日",},
	5:{3: u"憲法記念日",
	4: u"みどりの日",
	5: u"こどもの日",},
	7:{17: u"海の日",},
	9:{18: u"敬老の日",
	23: u"秋分の日",},
	10:{9: u"体育の日",},
	11:{3: u"文化の日",
	23: u"勤労感謝の日",},
	12:{23: u"天皇誕生日",},},
	2018:{1:{1: u"元日",
	8: u"成人の日",},
	2:{11: u"建国記念の日",
	12: u"振替休日",},
	3:{21: u"春分の日",},
	4:{29: u"昭和の日",
	30: u"振替休日",},
	5:{3: u"憲法記念日",
	4: u"みどりの日",
	5: u"こどもの日",},
	7:{16: u"海の日",},
	9:{17: u"敬老の日",
	23: u"秋分の日",
	24: u"振替休日",},
	10:{8: u"体育の日",},
	11:{3: u"文化の日",
	23: u"勤労感謝の日",},
	12:{23: u"天皇誕生日",
	24: u"振替休日",},},
	2019:{1:{1: u"元日",
	14: u"成人の日",},
	2:{11: u"建国記念の日",},
	3:{21: u"春分の日",},
	4:{29: u"昭和の日",},
	5:{3: u"憲法記念日",
	4: u"みどりの日",
	5: u"こどもの日",
	6: u"振替休日",},
	7:{15: u"海の日",},
	9:{16: u"敬老の日",
	23: u"秋分の日",},
	10:{14: u"体育の日",},
	11:{3: u"文化の日",
	4: u"振替休日",
	23: u"勤労感謝の日",},
	12:{23: u"天皇誕生日",},},
	2020:{1:{1: u"元日",
	13: u"成人の日",},
	2:{11: u"建国記念の日",},
	3:{20: u"春分の日",},
	4:{29: u"昭和の日",},
	5:{3: u"憲法記念日",
	4: u"みどりの日",
	5: u"こどもの日",
	6: u"振替休日",},
	7:{20: u"海の日",},
	9:{21: u"敬老の日",
	22: u"秋分の日",},
	10:{12: u"体育の日",},
	11:{3: u"文化の日",
	23: u"勤労感謝の日",},
	12:{23: u"天皇誕生日",},},
}

# ------------------------------------------------------------
## 関数
# ------------------------------------------------------------

# ------------------------------------------------------------
## 日付から日本の祝日データ取得
# @param date 日付
# @return 祝日データ Noneなら無し
def get_holiday_jp_from_date(date):
	return get_holiday_jp(date.year, date.month, date.day)

# ------------------------------------------------------------
## 日付から日本の祝日データ取得
# @param year 年
# @param month 月
# @param day 日
# @return 祝日データ Noneなら無し
def get_holiday_jp(year, month, day):
	try:
		return HOLIDAY_JP[year][month][day]
	except:
		return None
	return None

def string_compress(value, level=6, type="gzip"):
    fake_file = StringIO.StringIO()
    gz_file = GzipFile(None, 'wb', level, fileobj=fake_file)
    gz_file.write(value)
    gz_file.close()
    return fake_file.getvalue()

def string_to_sha512(text1, text2="sha"):
	return hashlib.sha512(text2 + text1).hexdigest()


def get_traceback_exc():
	tb = traceback.format_exc()

	try:
		return u"%s" % (tb.decode("utf-8"))
	except:
		pass
	try:
		return u"%s" % (tb.decode("cp932"))
	except:
		pass

	return tb

# ------------------------------------------------------------
## クラス
# ------------------------------------------------------------

# ------------------------------------------------------------
## メイン関数
# ------------------------------------------------------------
## メイン処理
if __name__ == '__main__':
	pass

# ------------------------------------------------------------
